package com.east.spark.excel;

import org.apache.commons.lang3.StringUtils;

public class ColumnTypeConvertor {

	public static String oracleToHive(String type) {
		type = StringUtils.lowerCase(type);
		type = StringUtils.trim(type);
		if (type.matches("varchar.*")) {
			return "string";
		}
		if (type.matches("bigint.*")) {
			return "decimal(38,0)";
		}
		if (type.matches("double.*") || type.matches("float.*")) {
			return "decimal(38,3)";
		}
		if (type.matches("datetime") || type.matches("timestamp")) {
			return "timestamp";
		}
		throw new RuntimeException("unknow jdbc type.");
	}

	public static String oracleToGbase(String type) {
		type = StringUtils.lowerCase(type);
		type = StringUtils.trim(type);
		if (type.matches("varchar.*")) {
			return "string";
		}
		if (type.matches("bigint.*")) {
			return "decimal(38,0)";
		}
		if (type.matches("double.*") || type.matches("float.*")) {
			return "decimal(38,3)";
		}
		if (type.matches("datetime") || type.matches("timestamp")) {
			return "timestamp";
		}
		throw new RuntimeException("unknow jdbc type.");
	}

}
